﻿var NearEast = function(){ };
NearEast.doing = false;//////////////////////////////////////////////

NearEast.toJSON = function(data) {
    if (typeof data == "string"){
    	try{
    		data = eval("(" + data + ")");
    	}catch(e){
    		if(console)
	    		console.log(e);
    	}
    }
    return data;
};

NearEast.val = function(e) {
    return $.trim(((typeof e == "string") ? $("#" + e) : e).val());
};
NearEast.val2 = function(e) {
    return escape(this.val(e));
};

NearEast.checkEM = function(em) {
    return /^([a-z0-9][a-z0-9_\-\.]*)@([a-z0-9][a-z0-9\.\-]{0,20})\.([a-z]{2,4})$/i.test(em); ////////////////////////////////////
};
NearEast.checkPW = function(pw) {////////////////////////////
    if (pw.length < 5) return 1;
    var c = 0;
    if (/[a-z]+/.test(pw)) c++;
    if (/[A-Z]+/.test(pw)) c++;
    if (/[0-9]+/.test(pw)) c++;
    if (/[^a-zA-Z0-9]+/.test(pw)) c++;
    if (c < 2) {
        var s = "0123456789abcdefghigklmnopqrstuvwxyz";
        var arr = pw.toLowerCase().split('');
        var idx = s.indexOf(arr[0]);
        if (idx > -1) {
            var arr2 = s.split('');
            for (var i = 0; i < arr.length; i++) {
                if (idx + 1 >= arr2.length || arr[i] != arr2[idx + i]) {
                    c++;
                    break;
                }
            }
        }
    }
    if (c > 1) {
        if (pw.length > 7) c++;
        if (/[^a-zA-Z0-9]+/.test(pw)) c++;
    }
    if (pw.replace(/(.)\1+/, "").length == 0) {
        c = 1;
    }
    if (c > 4) c = 4;

    return c;
};

NearEast.loading = function(e,t) {
    var load = document.createElement("div");
    load.id = "qiyiload";
    var pos = $(e).position();
//    load.style.position="absolute";
    load.style.left = pos.left + "px";
    load.style.top = (5+pos.top) + "px";
    load.style.width = e.offsetWidth - 11 + "px";
    load.style.height = e.offsetHeight - 5 + "px";
    load.style.zIndex = e.zIndex();
//    e.fadeTo(300,0.3);
//    e.attr('disabled',true);
    $(e).parent().append(load);
//    document.body.appendChild(load);

    NearEast.setLoad = function (len) {
        if ($("#qiyiload").length == 0) return;
        var s = "";
        for (var i = 0; i < len; i++) s += " .";
        if(t&&typeof t == "string") $("#qiyiload").html(t + s);
        else $("#qiyiload").html("Loading" + s);
        if (len == 6) len = 0; len++;
        setTimeout("NearEast.setLoad(" + len + ")", 400);
    };
    this.setLoad(6);
};
NearEast.loaded = function() {
    if ($("#qiyiload").length > 0) {
        $("#qiyiload").remove();
    }
};

NearEast.addCookie = function(name, value) {  
        var Days = 2;  
        var exp = new Date();  
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);  
        document.cookie = name + "=" + escape(value) + ";expires="+ exp.toGMTString();  
}
NearEast.getCookie = function(name) {  
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");  
        if (arr = document.cookie.match(reg))  
           return unescape(arr[2]);  
        else  
           return null;  
}
NearEast.delCookie = function(name) {  
        var exp = new Date();  
        exp.setTime(exp.getTime() - 2000000000);  
        var cval = getCookie(name);  
        if (cval != null)  
           document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";  
}
NearEast.GetPageSize = function() {  
        var actW, actH;  
        if(window.innerHeight && window.scrollMaxY) {  
        // Mozilla  
            actW = window.innerWidth + window.scrollMaxX;  
            actH = window.innerHeight + window.scrollMaxY;  
        } else if(document.body.scrollHeight > document.body.offsetHeight){  
        // all but IE Mac  
            actW = document.body.scrollWidth;  
            actH = document.body.scrollHeight;  
        } else if(document.body) { // IE Mac  
            actW = document.body.offsetWidth;  
            actH = document.body.offsetHeight;  
        }  
      
        var winW, winH;  
        if(window.innerHeight) { // all except IE  
            winW = window.innerWidth;  
            winH = window.innerHeight;  
        } else if (document.documentElement   
        && document.documentElement.clientHeight) {  
        // IE 6 Strict Mode  
            winW = document.documentElement.clientWidth;   
            winH = document.documentElement.clientHeight;  
        } else if (document.body) { // other  
            winW = document.body.clientWidth;  
            winH = document.body.clientHeight;  
        }  
      
        // for small pages with total size less then the viewport  
        var pageW = (actW<winW) ? winW : actW;  
        var pageH = (actH<winH) ? winH : actH;  
      
        return {PageW:pageW, PageH:pageH, WinW:winW, WinH:winH};  
}  